package com.cmict.data.system.api.dict;

import com.cmict.data.system.api.encodedetails.dict.EnCodeDataApi;
import com.cmict.data.system.api.encodedetails.dict.dto.EncodeDetailsDTO;
import com.cmict.data.system.convert.encode.EnCodeDataConvert;
import com.cmict.data.system.dal.dataobject.encode.EncodeDetailsDO;
import com.cmict.data.system.service.encode.EncodeDetailsService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

import static com.cmict.data.system.enums.ApiConstants.VERSION;

/**
 * 字典数据 API 实现类
 *
 * @author awesome
 */
@RestController
@DubboService(version = VERSION)
@Validated
public class EnCodeDataApiImpl implements EnCodeDataApi {

    @Resource
    private EncodeDetailsService encodeDetailsService;

    @Override
    public List<EncodeDetailsDTO> getDictEncodeDetailsList(Long encodeId) {
        List<EncodeDetailsDO> encodeDetailsDO = encodeDetailsService.selectList(encodeId);
        List<EncodeDetailsDTO> encodeDetailsDTOs = encodeDetailsDO.stream()
                .map(item -> EnCodeDataConvert.INSTANCE.convert01(item)).collect(Collectors.toList());
        return encodeDetailsDTOs;
    }
}
